package cn.ecut.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 当 WebServlet 中仅有一个值的时候，这个值就是 value 所表示的值
 **/

@WebServlet("/requestMethod01")
public class RequestMethodTest01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 获取端口
        System.out.println(  request.getLocalPort() );
        System.out.println( request.getRemotePort() );
        System.out.println( request.getServerPort() );

        // 获取 serverName
        System.out.println( request.getServerName() ); // localhost

//        System.out.println( request.getHttpServletMapping() );
//        System.out.println( request.getHttpServletMapping().getPattern() );
//        System.out.println( request.getHttpServletMapping().getServletName() );


        // /requestMethod01
        System.out.println( request.getRequestURI() );
        // http://localhost:8080/requestMethod01
        System.out.println( request.getRequestURL() );
        // get
        System.out.println( request.getMethod() );
        // http/1.1
        System.out.println( request.getProtocol() );
        // null
        System.out.println( request.getQueryString() );
    }
}
